﻿using System;
using System.Collections.Generic;
using System.Text;
using NFinal.Action;

namespace NFinal
{
    public class JsonResult : ContentResult
    {

        public JsonResult(string json=null):base(json, "application/json; charset=utf-8")
        {
        }
        public override void ExecuteResult<TContext, TRequest>(AbstractAction<TContext, TRequest> context)
        {
            if (this.Content == null)
            {
                context.Write(Newtonsoft.Json.JsonConvert.SerializeObject(context.ViewBag, new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter()));
            }
            else
            {
                context.Write(this.Content);
            }
            if (this.ContentType?.Length > 0)
            {
                context.contentType = this.ContentType;
            }
            context.Close();
        }
    }
}
